import java.util.HashSet;
import java.util.Set;
//https://leetcode.cn/problems/single-number-iii/
//解法1：
class Solution {
    public int[] singleNumber(int[] nums) {
        int x = 0;
        for (int num : nums) {
            x ^= num;
        }
        int last1 = x & -x;
        int[] ret = new int[2];
        for(int num : nums) {
            ret[(num & last1) == 0 ? 0 : 1] ^= num;
        }
        /**
         for (int num : nums) {
         int val = num & last1;
         if (val == 0) {
         ret[0] ^= num;
         } else {
         ret[1] ^= num;
         }
         } */
        return  ret;
    }
}
//解法2：
class Solution1 {
    public int[] singleNumber(int[] nums) {
        Set<Integer> set = new HashSet<>();
        for(int i = 0; i < nums.length; i++) {
            if(!set.contains(nums[i])) set.add(nums[i]);
            else set.remove(nums[i]);
        }
        int[] ret = new int[2];
        int index = 0;
        for(int x : set) {
            ret[index++] = x;
        }
        set = null;
        return ret;
    }
}